﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Gbi.Common
{
    /// <summary>
    /// Class for messaging service response
    /// </summary>
    [DataContract]
    public class MessagingResponse
    {
        #region Properties

        /// <summary>
        /// Gets or sets the error message.
        /// </summary>
        /// <value>
        /// The error message.
        /// </value>
        [DataMember(IsRequired = false, Name = "ErrorMessage")]
        public string ErrorMessage { get; set; }

        [DataMember(IsRequired = true, Name = "IsSuccess", EmitDefaultValue = true)]
        public bool IsSuccess
        {
            get
            {
                return string.IsNullOrWhiteSpace(this.ErrorMessage);
            }
            set
            {
                //DO nothing
            }
        }

        /// <summary>
        /// Gets or sets the key.
        /// </summary>
        /// <value>
        /// The key.
        /// </value>
        [DataMember(IsRequired = true, Name = "Key")]
        public Guid Key
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the created stamp.
        /// </summary>
        /// <value>
        /// The created stamp.
        /// </value>
        [DataMember(IsRequired = true, Name = "CreatedStamp")]
        public DateTime CreatedStamp
        {
            get;
            set;
        }

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="MessagingResponse"/> class.
        /// </summary>
        public MessagingResponse()
            : this(Guid.NewGuid())
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="MessagingResponse"/> class.
        /// </summary>
        /// <param name="key">The key.</param>
        public MessagingResponse(Guid key)
        {
            this.Key = key;
            this.CreatedStamp = DateTime.UtcNow;
        }

        #endregion
    }
}
